/*
  文章详情API
*/
import request from '@/utils/request.js'
// 获取文章详情
export const getArticleDetail = (articleId) => {
  return request({
    method: 'get',
    url: 'app/v1_0/articles/' + articleId
  })
}
// 关注文章接口
export const followArticle = (authorId) => {
  return request({
    method: 'post',
    url: 'app/v1_0/user/followings',
    data: {
      target: authorId
    }
  })
}

// 取消关注文章接口
export const unFollowArticle = (authorId) => {
  return request({
    method: 'delete',
    url: 'app/v1_0/user/followings/' + authorId
  })
}
// 点赞接口
export const likes = (articleId) => {
  return request({
    method: 'post',
    url: 'app/v1_0/article/likings',
    data: {
      target: articleId
    }
  })
}

// 取消点赞接口
export const unlikes = (articleId) => {
  return request({
    method: 'delete',
    url: 'app/v1_0/article/likings/' + articleId
  })
}

// 添加【不喜欢】接口
export const dislikes = (articleId) => {
  return request({
    method: 'post',
    url: 'app/v1_0/article/dislikes',
    data: {
      target: articleId
    }
  })
}

// 取消【不喜欢】接口
export const undislikes = (articleId) => {
  return request({
    method: 'delete',
    url: 'app/v1_0/article/dislikes/' + articleId
  })
}

// 获取文章的评论
export const getComments = (articleId, offset) => {
  return request({
    method: 'get',
    url: 'app/v1_0/comments',
    params: {
      // a表示文章的评论;c表示回复评论的数据
      type: 'a',
      // 评论的文章的id或者，回复的评论的id
      source: articleId,
      // 分页参数（评论的id）
      offset: offset,
      // 每页的条数
      limit: 10
    }
  })
}
// 发表评论接口
export const comment = (options) => {
  return request({
    method: 'post',
    url: 'app/v1_0/comments',
    data: {
      target: options.target,
      content: options.content,
      art_id: options.articleId
    }
  })
}
